
<#include "/common/head.html"/>
    
    <table id="dg"></table>
    <div id="tb" style="padding:2px 5px;">
        <div class="wrap_search">
        </div>
        <div style="text-align: left; margin:6px;">
            <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" plain="true" onclick="add()">增加</a>
            <a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true" onclick="update()">编辑</a>
            <a href="javascript:void(0)" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove" plain="true" onclick="del()">删除</a>
            <a href="javascript:void(0)" class="easyui-linkbutton detailBtn" iconCls="glyphicon-map-marker" plain="true" onclick="detail()">详情</a>
            <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-export" plain="true" onclick="exportCsv()">导出</a>
            <!-- <a href="javascript:void(0)" class="easyui-linkbutton importBtn" iconCls="glyphicon-import" plain="true" onclick="importCsv()">导入</a> -->
            <div id="searchBtnWrap" style="float:right; padding-right:40px;">
                <a href="javascript:void(0)" class="easyui-linkbutton color1" iconCls="glyphicon-search" onclick="zcurdSearch(this)">搜索</a>
                <a href="javascript:void(0)" class="easyui-linkbutton color2" iconCls="glyphicon-repeat" onclick="flushPage()">重置</a>
            </div>
        </div>
    </div>
    

<script type="text/javascript">
var datagrid = $("#dg");
var out_status="${out_status!}"
var param1 = {"queryParams[outstorage_id]":"${outstorage_id!}"};

var dgOptions = {
        rownumbers:true,
    	fit:true,
    	border:false,        
    	url:'listData',
    	method:'post',
    	toolbar:'#tb',
    	pageSize: 20,
    	pagination:true,
    	multiSort:true,
        queryParams: param1,
        
        columns: [[
		         {field:'id', checkbox:true}
	           	 //,{field:'outstorage_id', title: '关联出库单号', width:120, sortable: true}
	           	 ,{field:'mat_no', title: '物料编号', width:80, sortable: true}
	           	 ,{field:'mat_name', title: '物料名', width:100, sortable: true}
	           	 ,{field:'mat_std', title: '规格', width:120, sortable: true}
	           	 ,{field:'mat_unit', title: '单位', width:60, sortable: true}
	           	 ,{field:'mat_num', title: '数量', width:60, sortable: true}
	           	 ,{field:'mat_price', title: '单价', width:60, sortable: true}
	           	 ,{field:'mat_sum', title: '金额', width:60, sortable: true}
	           ]]
	};
$(function() {
	handleAuthDataRule();
	datagrid.datagrid(dgOptions);
});

function zcurdSearch() {
	var param = zcurdGetParam();
	datagrid.datagrid("load", {
		queryParams: param
	})
}

function zcurdGetParam() {
	var param = {"outstorage_id":"${outstorage_id!}"};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param[$(item).attr("name")] = $(item).val();	
		}
	});
	return param;
}

function getInitParam() {
	var param = {"outstorage_id":"${outstorage_id!}"};;
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param["queryParams[" + $(item).attr("name") + "]"] = $(item).val();	
		}
	});
	return param;
}

var initPara = zcurdGetParam();
function add() {
	if(out_status=="草稿"){
		top.window.subPage.loadCurrDatagrid = function() {
			showMsg("增加成功！");
			datagrid.datagrid("load");
		}
		top.openWindow("出库单明细表-增加", getCurrUrl("addPage") + "?" + $.param(initPara), {size: '600x400'});
	}
	else {
		showWarnMsg("已发布&已完成的出库单不能再增加！");
	}
}

function update() {
	if(out_status=="草稿"){
		var rowsSel = datagrid.datagrid("getSelections");
		if(rowsSel.length != 1) {
			showWarnMsg("请选择需要编辑的一条数据！");
			return;
		}
		var id = rowsSel[0].id;
		top.window.subPage.loadCurrDatagrid = function() {
			showMsg("更新成功！");
			datagrid.datagrid("reload");
		}
		top.openWindow("出库单明细表-编辑", getCurrUrl("updatePage") + "?id=" + id, {size: '600x400'});
	}
	else{
		showWarnMsg("已发布&已完成的出库单不能再修改！");
	}
}

function del() {
	if(out_status=="草稿"){
		var ids = [];
		$.each(datagrid.datagrid("getSelections"), function(i, item) {
			ids.push(item.id);
		});
		if(ids.length < 1) {
			showWarnMsg("请选择需要删除的数据！");
			return;
		}
		confirmMsg("确认删除？", function() {
			$.post("delete", {id: ids}, function(data) {
				showMsg("删除成功！");
				datagrid.datagrid("reload");
			});
		});
	}
	else{
		showWarnMsg("已发布&已完成的出库单不能删除物料明细！");
	}
}

function detail() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要查看的一条数据！");
		return;
	}
	var id = rowsSel[0].id;
	top.openWindow("出库单明细表-详情", getCurrUrl("detailPage") + "?id=" + id, {size: '600x400'});
}

function exportCsv() {
	var option = datagrid.datagrid("options");
	var param = option.queryParams;
	param.sortName = option.sortName;
	param.sortOrder = option.sortOrder;
	window.location.href = "exportCsv?" + $.param(param);
}
function importCsv() {
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("导入成功！");
		datagrid.datagrid("load");
	}
	top.openWindow("出库单明细表-导入", getCurrUrl("importCsvPage") + "?" + $.param(initPara), {size: '600x400'});
}
//按钮事件

/**
 * 打开子页
 */
var _openSubPageFlag = false;
function _openSubPage(pageUrl) {
	if(!_openSubPageFlag) {
		$("#subLayout").layout("expand", "east");
		setTimeout(function() {
			$("#subIframe").attr("src", pageUrl);
		}, 600);
		_openSubPageFlag = true;
	}else {
		$("#subIframe").attr("src", pageUrl);
	}
}

//扩展js
</script>

<#include "/common/dialogWindow.html"/>
<#include "/common/foot.html"/>
